<template>
	<view class="container">
		<view class="address_list">
			<view class="list flex flex-align flex-bt" v-for="(res,index) in siteList" :key="index">
				<view class="left">
					<view class="one flex flex-align">
						<view class="name">{{ res.name }}</view>
						<view class="mobile ">{{ res.phone }}</view>
						<view class="moren" v-if="res.type==1">默认</view>
					</view>
					<view class="two text_two">{{res.province}}{{res.city}}{{res.area}}{{res.address}}</view>
				</view>
				<view class="right"><tui-icon name='evaluate' color='#4d4d4d' :size='22' @click="toAddSite('/pages/address/eit_address?data='+JSON.stringify(res))"></tui-icon></view>
			</view>
			<view class="btn hei add_address" @click="toAddSite('/pages/address/eit_address')">新增收货地址</view>
		</view>
		<view class="empty-box" v-if='siteList.length==0'>
			<image src="https://firework.cyx.zzcyx1688.cn/web/static/noCart.png" mode=""></image>
			<view>暂无数据</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				siteList: [],
				page:1,
				is_show:false
			}
		},
		onLoad() {
	
		},
		onShow() {
				let that = this
				that.page = 1
				that.siteList = []
				that.getData()
			},
			onReachBottom() {
				let that = this
				if(!that.is_show){return false}
				that.page++
				that.getData()
			},
			methods: {
				getData() {
					let that = this
					that.tui.request("api.auth.address/get", "GET", {page:that.page}, false, true, true).then((res) => {
						console.log(res)
						that.siteList = that.siteList.concat(res.data.list)
						if(res.data.list.length<20){
							that.is_show = false
						}else{
							that.is_show = true
						}
					}).catch((res) => {})
					
					
				},
				del(e){
					let that = this
					that.tui.request("v1/user/addresses/"+e, "DELETE", {}, false, true, true).then((res) => {
						that.page = 1
						that.siteList = []
						that.getData()
					}).catch((res) => {})
				},
				eit(e){
					uni.navigateTo({
					    url: '/pages/address/eitSite?id='+e
					});
				},
				toAddSite(e){
					uni.navigateTo({
					    url: e
					});
				}
			}
		};
</script>

<style lang="scss">
	page{background: #f5f5f5;}
	.address_list{padding-top: 30rpx;padding-bottom: 160rpx;
		.list{margin:0 30rpx 30rpx;background: #fff;padding: 30rpx;border-radius: 10rpx;
			.left{width: 500rpx;
				.one{margin-bottom: 15rpx;
					.name{font-weight: bold;font-size: 30rpx;}
					.mobile{font-size: 26rpx;color: #808080;margin: 0 20rpx;}
					.moren{background: #fbeaf0;color: #bd0101;padding: 0 14rpx;}
				}
			}
		}
	}
	.add_address{position: fixed;bottom: 60rpx;left: 30rpx;width: 690rpx;}
	.btn{background: #bbe68c;color: #fff;text-align: center;line-height: 90rpx;}
</style>